package com.joysw.ui;

import butterknife.ButterKnife;
import butterknife.InjectView;

import com.joysw.R;
import com.joysw.ui.fragment.DtqFrgment;
import com.joysw.ui.fragment.FxFragment;
import com.joysw.ui.fragment.FxjlFragment;
import com.joysw.ui.fragment.GysFragment;
import com.joysw.ui.fragment.WdFragment;

import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;

/**
 * 
* @Title: MainActivity.java 
* @Package com.joysw.ui 
* @Description: Home页面
* @author LIMINGYAN  
* @date 2015年3月28日 上午7:39:14 
* @version V1.0
 */
public class MainActivity extends BaseActivity implements OnClickListener{
	private static final String TAG = "MainActivity";

	@InjectView(R.id.buttom_dtq)
	ImageButton mButtomDtq;
	@InjectView(R.id.buttom_gys)
	ImageButton mButtomGys;
	@InjectView(R.id.buttom_fxjl)
	ImageButton mButtomFxjl;
	@InjectView(R.id.buttom_fx)
	ImageButton mButtomFx;
	@InjectView(R.id.buttom_wd)
	ImageButton mButtomWd;
	
	//当前buttom上显示的button
	private View mCurrentButton;
	
    @Override
    protected void onCreate(Bundle arg0) {
    	// TODO Auto-generated method stub
    	super.onCreate(arg0);
    	setContentView(R.layout.activity_main);
    	ButterKnife.inject(this);
    	
    	initView();
    }
    
    private void initView(){
    	mButtomDtq.setOnClickListener(this);
    	mButtomGys.setOnClickListener(this);
    	mButtomFxjl.setOnClickListener(this);
    	mButtomFx.setOnClickListener(this);
    	mButtomWd.setOnClickListener(this);
    	
    	mButtomDtq.performClick();//主动去调用控件的点击事件
    }

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		FragmentManager fm=getSupportFragmentManager();
		FragmentTransaction ft=fm.beginTransaction();
		switch (v.getId()) {
			case R.id.buttom_dtq:
				DtqFrgment dtqFrgment = new DtqFrgment();
				ft.replace(R.id.fl_content, dtqFrgment,MainActivity.TAG);
				ft.commit();
				setButton(v);
				break;
			case R.id.buttom_gys:
				GysFragment gysFragment = new GysFragment();
				ft.replace(R.id.fl_content, gysFragment,MainActivity.TAG);
				ft.commit();
				setButton(v);
				break;
			case R.id.buttom_fxjl:
				FxjlFragment fxjlFragment = new FxjlFragment();
				ft.replace(R.id.fl_content, fxjlFragment,MainActivity.TAG);
				ft.commit();
				setButton(v);
				break;
			case R.id.buttom_fx:
				FxFragment fxFragment = new FxFragment();
				ft.replace(R.id.fl_content, fxFragment,MainActivity.TAG);
				ft.commit();
				setButton(v);
				break;
			case R.id.buttom_wd:
				WdFragment wdFragment = new WdFragment();
				ft.replace(R.id.fl_content, wdFragment,MainActivity.TAG);
				ft.commit();
				setButton(v);
				break;	
		}
	}
	
	private void setButton(View v){
		if(mCurrentButton!=null&&mCurrentButton.getId()!=v.getId()){
			mCurrentButton.setEnabled(true);
		}
		v.setEnabled(false);
		mCurrentButton=v;
	}

}
